<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分享上传</title>
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="/main/css/style.css">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <script src="/main/js/jquery-1.12.3.min.js"></script>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script>
        wx.config({
            debug: false,
            appId: "{%$signPackage.appId|default:''%}",
            timestamp: "{%$signPackage.timestamp|default:''%}",
            nonceStr: "{%$signPackage.nonceStr|default:''%}",
            signature: "{%$signPackage.signature|default:''%}",
            jsApiList: [
                'chooseImage',
                'getLocalImgData'
            ]
        });
        wx.ready(function () {
            var count=9;

            $(".addPic").click(function () {
                wxChooseImage();
            })

            $(".tj_btn").click(function () {
                var  localData=[];
                $.each($(".dataimg"), function (k, v) {
                    localData.push(v.getAttribute('src'));

                })
                if(localData.length>0){
                    $.ajax({
                        url: "/api/downimg.json",
                        type: "post",
                        async: "false",
                        dataType: "text",
                        data: {
                            tk_name:"{%$tk_name%}",
                            tk_value:"{%$tk_value%}",
                            mediatype:$("input[name=pic_option]:checked").val(),
                            localData: localData,
                        },
                        beforeSend:function () {
                            $(".loading_page").show();
                        },
                        success: function (data) {
                            $(".loading_page").hide();
                            alert('提交成功');
                            window.location.reload();
                            return false;
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $(".loading_page").hide();
                            alert('提交失败');

                        },
                    });
                }else{
                    alert('请选择图片');return false;
                }





            })


            //拍照或从手机相册中选图接口
            function wxChooseImage() {
                wx.chooseImage({
                    count: count,
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认
                    success: function (res) {
                        var localId = res.localIds;
                        var length =localId.length;
                        for (var i = 0; i < length; i++) {
                            wx.getLocalImgData({
                                localId: localId[i], // 图片的localID
                                success: function (res) {

                                    var localData = res.localData; // localData是图片的base64数据，可以用img标签显示
                                    var arr=localData.split(',');

                                    if(arr.length>1){
                                        $("#showlist").append("<div class='pic_sub '><img class='dataimg' src='" + localData+ "'></div>");
                                    }else{
                                        $("#showlist").append("<div class='pic_sub '><img class='dataimg' src='data:image/jgp;base64," + localData+ "'></div>");
                                    }

                                    count--;
                                    if (count == 0) {
                                        $(".addPic").hide();
                                    }
                                }
                            });



                        }
                    }

                });
            }



        });

    </script>

</head>
<body>
<!--fixed remove-->
<section class="fixed" style="z-index:999;width: 100%;height: 100%;background-color: #000;position: fixed;left: 0;top: 0;"></section>
<!--fixed remove-->
<section class="fixed" style="z-index:999;width: 100%;height: 100%;background-color: #000;position: fixed;left: 0;top: 0;"></section>
<!--上传分享-->
<div class="upload_page page_item">
    <div class="header clearfix">
        <div class="c_left">
            <img src="{%$user.headimg|default:'/main/img/avator.jpg'%}">
        </div>
        <div class="c_right">
            <p class="title">{%$user.username|default:''%}</p>
            <p class="desc">
                <span>兑换积分:<em>{%$user.intergtal|default:0%}</em></span></p>
        </div>
        <a class="upload_record" href="/sharelist">上传记录&gt;</a>
    </div>
    <!--选择图片-->

    <div class="pic_box clearfix">
        <div id="showlist"></div>
        <div class="addPic pic_sub"></div>
    </div>
    <div class="checkbox">
        <label for="zf" class="ordinary"><input type="radio" name="pic_option" id="zf" value="转发">转发</label>
        <label for="yc" class="ordinary"><input type="radio" name="pic_option" id="yc" value="原创">原创</label>
        <label for="qfx" class="ordinary"><input type="radio" name="pic_option" id="qfx" value="群分享">群分享</label>
        <label for="wbfx" class="ordinary ordinary_focus"><input type="radio" name="pic_option" id="wbfx" value="微博分享">微博分享</label>
    </div>
    <span class="tj_btn">提交</span>
    <p class="tips">上传图片会在上传成功5个工作日内审核</p>
    <!--add pops-->
    <div class="loading_page dno">
            <span class="loading_pic">
                <img src="/main/img/loading-1.gif">
            </span>
    </div>
    <!--add pops-->
</div>
</body>


<script src="/main/js/common.js"></script>
<script>

    $(window).load(function () {
        checkweichatevent();
        touchEvent();
        $('input[name="pic_option"]').on('click',function(){
            $(this).parents('.checkbox').find('.ordinary').removeClass('ordinary_focus');
            $(this).parent().addClass('ordinary_focus')
        });
    });
</script>
</html>